<?php
namespace app\controllers;
use yii\web\Controller;
use yii\web\Cookie;
use app\models\Country;

class IndexController extends Controller{
    
    public function beforeAction($action){
        echo 'than is before';
        return true;            //不写之后的不会执行
    }
    
    public function init(){
        echo 'fist is init';
    }
    
    public function actionIndex(){
//         echo 'is Index index';die;
//         $request = \Yii::$app->request->get('id',20);
        
//         echo $request;
        
//         if (\Yii::$app->request->isGet) {
//             echo 'is get method';
//         }
        
//         echo \Yii::$app->request->userIP;
//         echo \Yii::$app->request->url;

//         $res = \Yii::$app->response;
// //         $res->statusCode = '404';
//         $res->headers->add('pragma','no-cache');
//         $res->headers->add('location','https://www.baidu.com/');
//         $this->redirect('https://www.baidu.com/',302);
//         $res->headers->add('content-disposition','attachment; filename="a.jpg"');
//         $res->sendFile('./robots.txt');
//         $cookies = \Yii::$app->response->cookies;
//         $arr = array('name'=>'user','value'=>'zhangsan');
//         $cookies -> add(new Cookie($arr));
//         $cookies->remove('user');

//         $cookies = \Yii::$app->request->cookies;
//         echo $cookies->getValue('user',20);
        
        $this->layout = false;
        return $this->render('index');
        
        
        // 获取 country 表的所有行并以 name 排序
//         $countries = Country::find()->orderBy('name')->asArray()->all();
        
// //         print_r($countries);die;
// //         // 获取主键为 “US” 的行
//         $country = Country::findOne('US');
        
//         // 输出 “United States”
//         echo $country->name;
        
//         // 修改 name 为 “U.S.A.” 并在数据库中保存更改
//         $country->name = 'U.S.A.';
//         $country->save();
    }
}   